<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑职位 - HRM系统</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <link rel="stylesheet" th:href="@{/css/position-edit.css}">
</head>
<body>
<div class="dashboard">
    <header class="header">
        <div class="logo">HRM系统</div>
        <div class="user-info">
            <span th:text="${currentUser.realName}"></span>
            <span class="role-badge" th:text="${currentUser.roleId.roleName}"></span>
            <a href="/logout" class="logout-btn">退出</a>
        </div>
    </header>
    <main class="position-edit-container">
        <!-- 返回按钮 -->
        <div class="back-container">
            <a th:href="@{/position}" class="btn btn-back">← 返回职位列表</a>
        </div>

        <!-- 页面标题 -->
        <div class="module-header">
            <h1 class="module-title">编辑职位信息</h1>
        </div>

        <!-- 编辑表单 -->
        <form th:action="@{/position/edit/{id}(id=${position.positionId})}" method="post" class="edit-form">
            <!-- 基本信息区 -->
            <div class="form-section">
                <h2 class="section-title">基本信息</h2>
                <div class="form-grid">
                    <div class="form-group">
                        <label for="positionName">职位名称</label>
                        <input type="text" id="positionName" name="positionName"
                               th:value="${position.positionName}" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="positionCode">职位代码</label>
                        <input type="text" id="positionCode" name="positionCode"
                               th:value="${position.positionCode}" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="departmentID">所属部门</label>
                        <select id="departmentID" name="departmentID" class="form-control" required>
                            <option th:each="dept : ${departments}"
                                    th:value="${dept.departmentID}"
                                    th:text="${dept.departmentName}"
                                    th:selected="${position.departmentID.departmentID == dept.departmentID}">
                            </option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="positionRoleID">职位角色</label>
                        <select id="positionRoleID" name="positionRoleID" class="form-control" required>
                            <option th:each="role : ${roles}"
                                    th:value="${role.roleId}"
                                    th:text="${role.roleName}"
                                    th:selected="${position.positionRoleID.roleId == role.roleId}">
                            </option>
                        </select>
                    </div>
                </div>
            </div>

            <!-- 薪资福利区 -->
            <div class="form-section">
                <h2 class="section-title">薪资福利</h2>
                <div class="form-grid">
                    <div class="form-group">
                        <label for="maxHeadCount">最大编制人数</label>
                        <input type="number" id="maxHeadCount" name="maxHeadCount"
                               th:value="${position.maxHeadCount}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="baseSalary">基本工资</label>
                        <input type="number" step="0.01" id="baseSalary" name="baseSalary"
                               th:value="${position.baseSalary}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="allowance">津贴</label>
                        <input type="number" step="0.01" id="allowance" name="allowance"
                               th:value="${position.allowance}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="annualLeaveDays">年假天数</label>
                        <input type="number" step="0.5" id="annualLeaveDays" name="annualLeaveDays"
                               th:value="${position.annualLeaveDays}" class="form-control">
                    </div>
                </div>
            </div>

            <!-- 状态设置 -->
            <div class="form-section">
                <h2 class="section-title">状态设置</h2>
                <div class="form-group">
                    <label class="switch">
                        <input type="checkbox" id="status" name="status" th:checked="${position.status}">
                        <span class="slider round"></span>
                    </label>
                    <span class="status-label" th:text="${position.status} ? '启用' : '禁用'"></span>
                    <!-- 添加隐藏字段确保禁用状态也能提交 -->
                    <input type="hidden" name="_status" value="on"/>
                </div>
            </div>

            <!-- 表单操作按钮 -->
            <div class="form-actions">
                <button type="submit" class="btn btn-primary">保存更改</button>
                <button type="button" class="btn btn-cancel" onclick="history.back()">取消</button>
            </div>
        </form>
    </main>
</div>
<script th:src="@{/js/position-edit.js}"></script>
</body>
</html>